package com.ayu.scalalearn.chapter06

/**
  * @Author 徐林玉
  * @Description Test12TraitOverlying
  * @Date 2022/7/29 15:51
  * @Version 1.0
  */
object Test12TraitOverlying {

  def main(args: Array[String]): Unit = {

    //钻石问题特征叠加
    //1.优先使用特质。一个类扩展多个特质是很方便的，但却只能扩展一个抽象类。
    //2.如果你需要构造函数参数，使用抽象类。因为抽象类可以定义带参数的构造函数， 而特质不行（有无参构造）。
    val ball: MyBall = new MyBall();

    println(ball.describe())

  }


  trait Ball {

    def describe(): String = "Ball"
  }

  trait CategoryBall extends Ball {


    val category: String = "Foot"

    override def describe(): String = category + "-" + super.describe()
  }

  trait ColorBall extends Ball {

    val color: String = "Red"

    override def describe(): String = color + "-" + super.describe()
  }


  class MyBall extends CategoryBall with ColorBall {

    override def describe(): String = "i have a " + super[CategoryBall].describe()
  }

}


